﻿<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8" />
<link href="../css/bootstrap.min.css" rel="stylesheet" />
<link href="../css/font-awesome.min.css" rel="stylesheet" />
<link href="../js/plugins/layer/skin/layer.css" rel="stylesheet" />
<link href="../js/plugins/layer/skin/layer.ext.css" rel="stylesheet" />
<script src="../js/jquery-2.1.1.min.js"></script>
<script src="../js/plugins/layer/layer.min.js"></script>
<script src="../js/plugins/linq/linq.js"></script>
<script src="../weixin/js/common.js"></script>
<script src="../js/tableToExcel.js"></script>
<script src="../js/extTools.js"></script>
<style>
    table {
        font-size: 15px;
        height: auto;
        width: auto;
        text-align: center!important;
    }
    table th {
        text-align: center!important;
        min-width: 100px;
        background-color: darkgrey;
    }
    .market{
        background-color: lightyellow;
    }
    .otherData {
        background-color: #c5d9f1;
    }
    .clossing {
        background-color: #f2dcdb;
    }
    .saleBillPartQty {
        background-color: #dcffd9;
    }
    .kpiQty {
        background-color: #fde9d9;
    }
    .nowData {
        background-color: #b7dee8;
    }
</style>
<html>
<head>
    <title>分部时段跟踪报表</title>
</head>
<body>
<div style="margin-top: 5px; margin-left: 5px">
    <a class='btn btn-success btn-xs btn-info' onclick='tableToExcelMethod(exportReportTotal,exportReport)'>导出</a>
    <a class='btn btn-success btn-xs btn-info' onclick='exportReportDetail()'>导出</a>
    <table border="1" id="exportReportTotal" title="全国销售汇总表" hidden="hidden">
        <thead id="exTable_headTotal">
        </thead>
        <tbody id="exTable_bodyTotal">
        </tbody>
    </table>
    <table border="1" id="exportReport" title="省份销售汇总明细" hidden="hidden">
        <thead id="exTable_head">
        </thead>
        <tbody id="exTable_body">
        </tbody>
    </table>
    <table border="1" id="exportReportDetail" title="销售明细">
        <thead id="exTable_headDetail">
        </thead>
        <tbody id="exTable_bodyDetail">
        </tbody>
    </table>
</div>
</body>
</html>

<script type="text/javascript">
    $(function() {
        loadData();
    });
    
    var loadData = function () {
        $.post("VendCustHandler.ashx",
            {
                "action": "GetVendCustSalesReport",
                "vendCustID": 1,
                "periodYear": 1,
                "startDate": "2017-11-11",
                "endDate": "2017-11-11",
                "page": "1",
                "size": "100",
            },
            function (data) {

                var exTBodyTotal = $("#exTable_bodyTotal");
                var exTHeadTotal = $("#exTable_headTotal");

                var exTBody = $("#exTable_body");
                var exTHead = $("#exTable_head");

                var exTBodyDetail = $("#exTable_bodyDetail");
                var exTHeadDetail = $("#exTable_headDetail");

                if (data.Success == true) {

                    var exThMarkTotal = "<tr>";
                    exThMarkTotal += "<th>货号</th><th>供应商</th><th>范围</th><th>售罄率</th><th>销售金额</th><th>销售数量</th><th>成本价</th><th>当前仓存</th><th>当前店存</th>";
                    exThMarkTotal += "</tr>";

                    var exInTHead = "<tr>";
                    exInTHead +=
                        "<th>货号</th><th>省份</th><th>仓库/店铺</th><th>售罄率</th><th>销售金额</th><th>销售数量</th><th>当前库存</th>";
                    exInTHead += "</tr>";

                    var exInTHeadDetail = "<tr>";
                    exInTHeadDetail +=
                        "<th>省份</th><th>仓库</th><th>仓库类型</th><th>店铺性质</th><th>供应商</th><th>货号</th><th>成本价</th><th>颜色</th><th>售罄率</th><th>尺码</th><th>销售金额</th><th>销售数量</th><th>当前库存</th>";
                    exInTHeadDetail += "</tr>";

                    exTHeadTotal.empty();
                    exTHeadTotal.append(exThMarkTotal);

                    exTHead.empty();
                    exTHead.append(exInTHead);

                    exTHeadDetail.empty();
                    exTHeadDetail.append(exInTHeadDetail);
                    
                    if (data.Data.resultTotalList.length > 0) {
                        
                        var exTbHtmlTotal = "";

                        var exTbHtml = "";
                        
                        data.Data.resultTotalList.map(function (rtOutLi) {

                            var materialID = rtOutLi.MaterialID;

                            var exOutTBodyTotal = "<tr>";

                            exOutTBodyTotal += "<td>" + materialID + "（" + rtOutLi.ColorName + "）</td>";
                            exOutTBodyTotal += "<td>" + rtOutLi.VendCustName + "</td>";
                            exOutTBodyTotal += "<td>" + rtOutLi.DataText + "</td>";
                            exOutTBodyTotal += "<td>" + (Y.checkNull(rtOutLi.SaleRate) ? '0.00' : (rtOutLi.SaleRate * 100).toFixed(2)) + "%</td>";
                            exOutTBodyTotal += "<td>" + (Y.checkNull(rtOutLi.SaleAmount) ? '0.00' : rtOutLi.SaleAmount.toFixed(2)) + "</td>";
                            exOutTBodyTotal += "<td>" + rtOutLi.SaleQty + "</td>";
                            exOutTBodyTotal += "<td>" + (Y.checkNull(rtOutLi.CostPrice) ? '0.00' : rtOutLi.CostPrice.toFixed(2)) + "</td>";
                            exOutTBodyTotal += "<td>" + rtOutLi.StockQty + "</td>";
                            exOutTBodyTotal += "<td>" + rtOutLi.ShopQty + "</td>";

                            exOutTBodyTotal += "</tr>";

                            exTbHtmlTotal += exOutTBodyTotal;

                            if (rtOutLi.resultTotalProvList.length > 0) {

                                rtOutLi.resultTotalProvList.map(function (rtInList) {
                                    
                                    
                                    rtInList.map(function (rtInLi) {
                                        var exInTBody = "<tr>";
                                        exInTBody += "<td>" + materialID + "</td>";
                                        exInTBody += "<td>" + rtInList[0].Province + "</td>";
                                        exInTBody += "<td>" + rtInLi.DataText + "</td>";
                                        exInTBody += "<td>" + (Y.checkNull(rtInLi.SaleRate) ? '0.00' : (rtInLi.SaleRate * 100).toFixed(2)) + "%</td>";
                                        exInTBody += "<td>" + (Y.checkNull(rtInLi.SaleAmount) ? '0.00' : rtInLi.SaleAmount.toFixed(2)) + "</td>";
                                        exInTBody += "<td>" + rtInLi.SaleQty + "</td>";
                                        exInTBody += "<td>" + rtInLi.Qty + "</td>";
                                        exInTBody += "</tr>";
                                        exTbHtml += exInTBody;

                                    });
                                });
                            }

                        });

                        exTBodyTotal.empty();
                        exTBodyTotal.append(exTbHtmlTotal);

                        exTBody.empty();
                        exTBody.append(exTbHtml);
                    } else {
                        exTHeadTotal.empty();
                        exTHeadTotal.append(exThMarkTotal);
                        var emptyTable = "<tr><td colspan='9'>暂无数据</td></tr>";
                        exTBodyTotal.empty();
                        exTBodyTotal.append(emptyTable);
                    }

                    if (data.Data.resultDetailList.length > 0) {

                        var exTbHtmlDetail = "";
                        
                        data.Data.resultDetailList.map(function (rdList) {

                            var rdLength = rdList.length;
                            var firstRD = rdList[0];
                            var exTBodyDetail = "<tr>";
                            exTBodyDetail += "<td rowspan='" + rdLength + "'>" + firstRD.Province + "</td>";
                            exTBodyDetail += "<td rowspan='" + rdLength + "'>" + firstRD.StockName + "</td>";
                            exTBodyDetail += "<td rowspan='" + rdLength + "'>" + firstRD.StockType + "</td>";
                            exTBodyDetail += "<td rowspan='" + rdLength + "'>" + firstRD.ShopType + "</td>";
                            exTBodyDetail += "<td rowspan='" + rdLength + "'>" + firstRD.VendCustName + "</td>";
                            exTBodyDetail += "<td rowspan='" + rdLength + "'>" + firstRD.MaterialID + "</td>";
                            exTBodyDetail += "<td rowspan='" + rdLength + "'>" + firstRD.CostPrice + "</td>";
                            exTBodyDetail += "<td rowspan='" + rdLength + "'>" + firstRD.ColorName + "</td>";
                            exTBodyDetail += "<td rowspan='" + rdLength + "'>" + (Y.checkNull(firstRD.SaleRate) ? '0.00' : firstRD.SaleRate.toFixed(2)) + "%</td>";

                            rdList.map(function (rdLi, index) {
                                if (index > 0) {
                                    exTBodyDetail += "<tr>";
                                }
                                exTBodyDetail += "<td>" + rdLi.SizeName + "</td>";
                                exTBodyDetail += "<td>" + (Y.checkNull(rdLi.SaleAmount) ? '0.00' : rdLi.SaleAmount.toFixed(2)) + "</td>";
                                exTBodyDetail += "<td>" + rdLi.SaleQty + "</td>";
                                exTBodyDetail += "<td>" + rdLi.Qty + "</td>";
                                exTBodyDetail += "</tr>";
                            });
                            exTbHtmlDetail += exTBodyDetail;
                        });

                        exTBodyDetail.empty();
                        exTBodyDetail.append(exTbHtmlDetail);

                    } else {
                        var emptyTableDetail = "<tr><td colspan='13'>暂无数据</td></tr>";
                        exTBodyDetail.empty();
                        exTBodyDetail.append(emptyTableDetail);
                    }
                }
            });
    }


    var exportReportDetail = function() {
        $.post("VendCustHandler.ashx",
            {
                "action": "ExportVendCustSalesReport",
                "vendCustID": 1,
                "periodYear": 1,
                "startDate": "2017-11-11",
                "endDate": "2017-11-11",
            },
            function (data) {
                if (data.Success) {
                    outExcle(data.Data);
                } else {
                    layer.alert(data.Message, {
                        icon: 1,
                        skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                    });
                }
            });
    }


</script>

